package com.hmall.cart.lisenter;

import com.hmall.cart.service.ICartService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

// Cart服务新建监听器 CartClearListener.java
@Component
@RequiredArgsConstructor
public class CartClearListener {
    private final ICartService cartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "cart.clear.queue1", durable = "true"),
            exchange = @Exchange(name = "trade.topic1", type = ExchangeTypes.TOPIC),
            key = "order.create1"
    ))
    public void listenOrderCreate(Map<String,Object> map){
        System.out.println(map);
        cartService.removeByItemIds(map);
    }
}